Skip to content

fix(checkbox): show labels after page navigation#31062

Open
OS-jacobbell wants to merge 2 commits intomainfrom
FW-7274
Open

fix(checkbox): show labels after page navigation#31062
OS-jacobbell wants to merge 2 commits intomainfrom
FW-7274

Conversation

@OS-jacobbell
Copy link
Copy Markdown
Contributor

Issue number: resolves #31052


What is the current behavior?

After a page navigation, ion-checkbox's onslotchange event fires before the element's textContent has been updated. It is called again after textContent becomes readable on Safari, but is not called again after the textContent becomes readable on Chrome and Firefox.

What is the new behavior?

  • Uses MutationObserver instead of onslotchange and fires specifically on character data changes. This ensures hasLabelContent is up to date.
  • MutationObserver does not fire on load, so hasLabelContent is initialized in connectedCallback

Does this introduce a breaking change?

  • Yes
  • No

@OS-jacobbell OS-jacobbell requested a review from a team as a code owner April 2, 2026 20:58
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview, Comment Apr 3, 2026 8:13pm

Request Review

@github-actions github-actions bot added the package: core @ionic/core package label Apr 2, 2026
@gnbm gnbm requested a review from ShaneK April 3, 2026 00:21
Copy link
Copy Markdown
Member

@brandyscarney brandyscarney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Please update the PR title before merging. 🙂

@OS-jacobbell OS-jacobbell changed the title fix(checkbox): use mutation observer instead of onslotchange fix(checkbox): show labels after page navigation Apr 7, 2026
Copy link
Copy Markdown
Member

@ShaneK ShaneK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good! A couple of minor concerns, though

});
this.validationObserver = new MutationObserver((mutations) => {
// Watch for label content changes
if (mutations.some((mutation) => mutation.type === 'characterData')) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only catches mutations to existing text nodes (.data changes). If the framework replaces slot children entirely, like an *ngIf toggling a label, or el.textContent = 'new' which removes all children and creates a new text node, that's a childList mutation and this won't fire. The original onSlotchange covered both cases.

Should childList: true go into the observe config alongside characterData: true? The condition here would just become mutation.type === 'characterData' || mutation.type === 'childList'. createSlotMutationController uses childList for the same reason.

Also, radio.tsx and toggle.tsx have the same get hasLabel() getter pattern that checkbox had before #30980, so they're vulnerable to the same bug. Probably follow-up tickets rather than scope creep here, but good to track.

attributes: true,
attributeFilter: ['class'],
characterData: true,
subtree: true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subtree: true applies to all observation types, not just characterData. So the attributeFilter: ['class'] now fires for descendant class changes too, not just the host element. It's harmless since the handler filters by mutation.type, but you could tighten the attributes branch with mutation.target === el to match the original observer's scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ion-checkbox doesn't show label from variable after navigating in Angular

3 participants